package com.yyq.dao;

import com.yyq.pojo.Order;
import com.yyq.pojo.User;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author yuanyueqiang
 * @Date 2021-11-29 23:30
 */
public interface OrderDao {


    /**
     * 查询结果集中得有uid字段, 做为用户的主键进行子查询
     * @return
     */
    @Results({
            @Result(property = "id",column = "id"),
            @Result(property = "orderName",column = "order_name"),
            @Result(property = "user",column = "uid",javaType = User.class,
                    one = @One(select = "com.yyq.dao.UserDao.getUserById"))
    })
    @Select("select * from `order`")
    List<Order> getOrderAndUser();

    @Select("select * from `order` where id=#{id}")
    Order getOrderById(Integer id);

    @Select("select * from `order` where uid=#{uid}")
    List<Order> getOrderByUserId(String uid);

}
